<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 数组中第 K 个独一无二的字符串 -->
    <script>
      var kthDistinct = (arr, k) => {
        // 创建Map
        let map = new Map()
        // 遍历数组，统计出现的个数
        for (let char of arr) {
          map.set(char, (map.get(char) || 0) + 1)
        }
        let res = []
        // 将出现1次的数，放入res
        for (let item of map) {
          if (item[1] === 1) res.push(item[0])
        }
        // 返回第k个，若没有，返回''
        return res[k - 1] || ''
      }
      console.log(kthDistinct(['d', 'b', 'c', 'b', 'c', 'a'], 2))
    </script>
  </body>
</html>
